﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Web;

namespace YmtAuth.Common.Utility
{
    public class CommonHelper
    {
        /// <summary>
        /// 是否是合法的 IPv4
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static bool IsValidIPv4(string ip)
        {
            if (string.IsNullOrEmpty(ip))
            {
                return false;
            }

            var ipArray = ip.Split(new char[] { '.' });
            if (ipArray.Length != 4)
                return false;

            int temp;
            foreach (var item in ipArray)
            {
                if (!Int32.TryParse(item, out temp)) return false;
            }

            return true;
        }
    }
}
